package component;

import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.InputValidator;
import com.intellij.openapi.ui.Messages;
import com.intellij.util.PairFunction;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;

/**
 * @Auther syc.
 * @Date 2016/11/10 15:49.
 */
public class ShowDailogComponent implements ApplicationComponent {
    public ShowDailogComponent() {
    }

    @Override
    public void initComponent() {
        // TODO: insert component initialization logic here
    }

    @Override
    public void disposeComponent() {
        // TODO: insert component disposal logic here
    }

    @Override
    @NotNull
    public String getComponentName() {
        return "ShowDailogComponent";
    }

    public void showDialog(String message) {

        // Show dialog with message

        Messages.showMessageDialog(message, "Notice", Messages.getInformationIcon());

    }

    public String showInputDialog(Project project, String notice, String initValue, String boxName) {



        return Messages.showInputDialog(project, notice, boxName, Messages.getQuestionIcon(), initValue, new InputValidator() {
            @Override
            public boolean checkInput(String s) {
                return true;
            }

            @Override
            public boolean canClose(String s) {
                return true;
            }
        });
    }

    public String showInputDialog(Project project, String notice, String boxName) {

        return Messages.showInputDialog(project, notice, boxName, Messages.getQuestionIcon());
    }

    public String showMultilineInputDialog(Project project, String notice, String initValue, String boxName) {
        return Messages.showMultilineInputDialog(project, notice, boxName, initValue, Messages.getQuestionIcon(), new InputValidator() {
            @Override
            public boolean checkInput(String s) {
                return true;
            }

            @Override
            public boolean canClose(String s) {
                return true;
            }
        });
    }

    public String showMultiDialog(String[] values, String initalValue) {
        return Messages.showEditableChooseDialog("一键启服包含服务器", "title", Messages.getQuestionIcon(), values, initalValue, new InputValidator() {
            @Override
            public boolean checkInput(String s) {
                return false;
            }

            @Override
            public boolean canClose(String s) {
                return false;
            }
        });
    }

    public int showCheckboxOkCancelDialog(int optionIndex, int focusedIndex) {
        return Messages.showCheckboxOkCancelDialog("message", "title", "checkboxtext", true, optionIndex, focusedIndex, Messages.getQuestionIcon());

    }

    public int showCheckboxMessageDialog(String[] options, int optionIndex, int focusedIndex) {
        return Messages.showCheckboxMessageDialog("message", "title", options, "checkboxtext", true, optionIndex, focusedIndex, Messages.getQuestionIcon(), new PairFunction<Integer, JCheckBox, Integer>() {
            @Override
            public Integer fun(Integer integer, JCheckBox jCheckBox) {
                return null;
            }
        });
    }

}
